package sis.report;

import static org.junit.Assert.assertEquals;
import static sis.report.RosterReport.NEWLINE;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;

import org.junit.Test;

import sis.studentinfo.Course;
import sis.studentinfo.CourseSession;
import sis.studentinfo.Session;

public class CourseReportTest {
	@Test
	public void testReport(){
		final Date date = new Date();
		CourseReport report = new CourseReport();
		report.add(create("ENGL", "101", date));
		report.add(create("CZEC", "200", date));
		report.add(create("ITAL", "410", date));
		report.add(create("CZEC", "220", date));
		report.add(create("ITAL", "330", date));
		
		assertEquals("CZEC 200" + NEWLINE +
				"CZEC 220" + NEWLINE +
				"ENGL 101" + NEWLINE +
				"ITAL 330" + NEWLINE +
				"ITAL 410" + NEWLINE,report.text());
	}
	
	private Session create(String name, String number, Date date) {
		return CourseSession.create(new Course(name, number), date);
	}

	@Test
	public void testSortStringsInNewList(){
		ArrayList<String> list = new ArrayList<String>();
		list.add("Heller");
		list.add("Kafka");
		list.add("Camus");
		list.add("Boyle");
		ArrayList<String> sortedList = new ArrayList<String>(list); //利用此方法，直接将一个list拷贝到另一个list中
		Collections.sort(sortedList);
		assertEquals("Boyle",sortedList.get(0));
		assertEquals("Camus",sortedList.get(1));
		assertEquals("Heller",sortedList.get(2));
		assertEquals("Kafka",sortedList.get(3));
		
		assertEquals("Heller",list.get(0));
		assertEquals("Kafka",list.get(1));
		assertEquals("Camus",list.get(2));
		assertEquals("Boyle",list.get(3));
	}
}
